/**
 * @author tibork
 */
Ext.namespace("Softab");

Softab.EntityField = function(){};
Softab.EntityField.prototype._id;
Softab.EntityField.prototype._name;
Softab.EntityField.prototype._type;
Softab.EntityField.prototype._formLocation;
Softab.EntityField.prototype._gridLocation;
Softab.EntityField.prototype._init = function(extFieldData, customFieldData){
	switch(extFieldData.type){
		case "TextField":
			return this.RenderAsTextField(extFieldData);//
			break;
		case "TextArea":
			return this.RenderAsTextArea(extFieldData);//
			break;
		case "HtmlEditor":
			return this.RenderAsHtmlEditor(extFieldData);//
			break;
		case "TimeField":
			return this.RenderAsTimeField(extFieldData);//
			break;
		case "DateField":
			return this.RenderAsDateField(extFieldData);//
			break;
		case "DiskFile":
			return this.RenderAsSingleFileUpload(extFieldData);//
			break;
		case "SSLookupField":
			return this.RenderAsSSLookupField(extFieldData, customFieldData);//
			break;
	}
}

Softab.EntityField.prototype.AlterName = function(){
	this._name = "altered";
	return this._name;
};

Softab.EntityField.prototype.RenderAsTextField= function(fieldData){
	var parsedData = new Object();
	for(var prop in fieldData){
		parsedData[prop] = fieldData[prop];
		if (fieldData[prop] == "true") {
			parsedData[prop] = true;
		}
		if(fieldData[prop] == "false"){
			parsedData[prop] = false;
		}
		
	}
	return new Ext.form.TextField(parsedData);
}

Softab.EntityField.prototype.RenderAsTextArea= function(fieldData){
	var parsedData = new Object();
	for(var prop in fieldData){
		parsedData[prop] = fieldData[prop];
		if (fieldData[prop] == "true") {
			parsedData[prop] = true;
		}
		if(fieldData[prop] == "false"){
			parsedData[prop] = false;
		}
		
	}
	return new Ext.form.TextArea(parsedData);
}

Softab.EntityField.prototype.RenderAsHtmlEditor= function(fieldData){
	var parsedData = new Object();
	for(var prop in fieldData){
		parsedData[prop] = fieldData[prop];
		if (fieldData[prop] == "true") {
			parsedData[prop] = true;
		}
		if(fieldData[prop] == "false"){
			parsedData[prop] = false;
		}
		
	}
	return new Ext.form.HtmlEditor(parsedData);
}

Softab.EntityField.prototype.RenderAsTimeField= function(fieldData){
	var parsedData = new Object();
	for(var prop in fieldData){
		parsedData[prop] = fieldData[prop];
		if (fieldData[prop] == "true") {
			parsedData[prop] = true;
		}
		if(fieldData[prop] == "false"){
			parsedData[prop] = false;
		}
	}
	return new Ext.form.TimeField(parsedData);
}

Softab.EntityField.prototype.RenderAsDateField= function(fieldData){
	var parsedData = new Object();
	for(var prop in fieldData){
		parsedData[prop] = fieldData[prop];
		if (fieldData[prop] == "true") {
			parsedData[prop] = true;
		}
		if(fieldData[prop] == "false"){
			parsedData[prop] = false;
		}
	}
	return new Ext.form.DateField(parsedData);
}

Softab.EntityField.prototype.RenderAsSingleFileUpload = function(fieldData){
	var parsedData = new Object();
	for(var prop in fieldData){
		parsedData[prop] = fieldData[prop];
		if (fieldData[prop] == "true") {
			parsedData[prop] = true;
		}
		if(fieldData[prop] == "false"){
			parsedData[prop] = false;
		}
	}
	parsedData['buttonCfg']={text: '', iconCls: 'upload-icon'};
	field = new Ext.form.FileUploadField(parsedData);
	return field;
}

Softab.EntityField.prototype.RenderAsSSLookupField = function(fieldData, customFieldData){
	
	field = new Ext.form.ButtonField({
	            id: 'lookup-field-id',
	            fieldLabel: 'Lookup Field',
				emptyText: 'No Selection Made',
				name: customFieldData.name,
				allowBlank: true,
	            //name: 'lookup-field',
				buttonText: 'Select lookup Field',
				valueField: customFieldData.valueField,
				textField: customFieldData.textField,
				//value: 'No Selection Made From Config Value prop',
				//selectedText: 'No Selection Made From Config',
				//selectedValue: 'GetLookup',
				iconCls: 'btn-add',
				handler:function(){
					//this.setSelectedText("ProgramaticalySet");
					//this.setSelectedValue("ValueSetProgramaticalySet");
					Softab.EntityLookupWindow(this, customFieldData.lookedUpEntityID, false, customFieldData.valueField, customFieldData.textField);
				}
			});
	return field;
}
